<% type = "StoreStaffAttendence" %>
<div class="main_top">
  <h2>考勤奖惩</h2>
</div>

<div class="details">
  <%= render "top_info" %>

  <div class="details_content attendance_reward_punishment" style="margin-left:50px;">
    <ul class="option_nav">
      <li><label>考勤<input type="radio" id="first_type" data-type="StoreStaffAttendence" data-operate="扣款" data-sort=".attendence-sort" data-head="attendence" checked></label></li>
      <li><label>奖励<input type="radio" data-type="StoreStaffReward" data-operate="奖励" data-sort=".reward-sort" data-head="reward"></label></li>
      <li><label>惩戒<input type="radio" data-type="StoreStaffDiscipline" data-operate="扣款" data-sort=".penalty-sort" data-head="penalty"></label></li>
      <li><label>加班<input type="radio" data-type="StoreStaffOvertime" data-operate="奖励" data-sort=".overtime-sort" data-head="overtime"></label></li>
    </ul>

    <div class="forms">
      <div class="type-select">
        <p id="attendence">考勤单</p>
        <p id="reward" style="display:none;">奖励单</p>
        <p id="penalty" style="display:none;">惩戒单</p>
        <p id="overtime" style="display:none;">加班单</p>
      </div>

      <%= form_for @event, url: ems_store_staff_events_path(store_staff_id: @staff.id)  do |form| %>
        <%= form.hidden_field :type, value: type, id: "type-hidden" %>
        <%= form.hidden_field :store_staff_id, value: @staff.id %>
        <table>
          <thead>
            <tr>
              <th>姓名</th>
              <th><%= @staff.full_name %></th>
              <th>部门</th>
              <th><%= @staff.store_department_name %></th>
              <th>职务</th>
              <th><%= @staff.store_position_name %></th>
            </tr>
          </thead>
          <tbody class="attendance share-tbody", id="tbody-class-swift">

            <tr class="attendence-sort text-indent-10">
              <th rowspan="2">考勤科目</th>
              <td colspan="5">
                <%= form.collection_radio_buttons :sort, EventType.collection(:StoreStaffAttendence), "id", "name" do |b| %>
                  <%= b.label { raw(b.text + b.radio_button) } %>
                <% end %>
              </td>
            </tr>
            <tr class="attendence-sort">
              <td colspan="5" class="text-align-center">
                <%= form.label :started_at, "起" %>
                <%= form.text_field :started_at, class: "width-122 margin-right-10 dateTimePickerAll" %>
                <%= form.label :ended_at, "止" %>
                <%= form.text_field :ended_at, class: "width-122 margin-right-10 a-end dateTimePickerAll" %>
                <label>共计</label>
                 <input type="text" name="store_staff_event[hour]" class="width-50 calculate-days"><nbsp1></nbsp1>小时
                 <p style="background:#fff;color:red;">
                   *注意: 如果起止时间跨月份，请分开添加记录，以免产生误差.
                 </p>
              </td>
            </tr>

            <tr class="reward-sort">
              <th >时间</th>
              <td colspan="2" class="text-indent-20">
                <%= form.text_field :occur_on, class: "width-122 margin-right-10 dateTimePicker" %>
              <th class="address">地点</th>
              <td colspan="2" class="text-indent-20"><input type="text"  value=""></td>
            </tr>
            <tr class="reward-sort">
              <th>性质</th>
              <td colspan="5" class="text-indent-20">
                <%= form.collection_radio_buttons :sort, EventType.collection(:StoreStaffReward), "id", "name" do |b| %>
                  <%= b.label { raw(b.text + b.radio_button) } %>
                <% end %>
              </td>
            </tr>

            <tr class="penalty-sort">
              <th >时间</th>
              <td colspan="2" class="text-indent-20">
                <%= form.text_field :occur_on, class: "width-122 margin-right-10 dateTimePicker" %>
              </td>
              <th class="address">地点</th>
              <td colspan="2" class="text-indent-20"><input type="text"  value=""></td>
            </tr>
            <tr class="penalty-sort">
              <th>性质</th>
              <td colspan="5" class="text-indent-20">
                <%= form.collection_radio_buttons :sort, EventType.collection(:StoreStaffDiscipline), "id", "name" do |b| %>
                  <%= b.label { raw(b.text + b.radio_button) } %>
                <% end %>
              </td>
            </tr>

            <tr class="overtime-sort text-indent-10">
              <th rowspan="2">加班事项</th>
              <td colspan="5">
                <%= form.collection_radio_buttons :sort, EventType.collection(:StoreStaffOvertime), "id", "name" do |b| %>
                  <%= b.label { raw(b.text + b.radio_button) } %>
                <% end %>
              </td>
            </tr>
            <tr class="overtime-sort">
              <td colspan="5" class="text-align-center">
                <%= form.label :started_at, "起" %>
                <%= form.text_field :started_at, class: "width-122 margin-right-10 dateTimePickerAll", disabled: true %>
                <%= form.label :ended_at, "止" %>
                <%= form.text_field :ended_at, class: "width-122 margin-right-30 a-end dateTimePickerAll", disabled: true %>
                <label>共计</label>
                <input type="text" name="store_staff_event[hour]" disabled="true" class="width-50 calculate-days"><nbsp1></nbsp1>小时
                <p style="background:#fff;color:red;">
                  *注意: 如果起止时间跨月份，请分开添加记录，以免产生误差.
                </p>
              </td>
            </tr>
            </tbody>

            <tbody class="attendance">
            <tr>
              <th>描述</th>
              <td colspan="5">
                <!-- <textarea rows="10"></textarea> -->
                <%= form.text_area :remark, rows: 10 %>
                <div class="text-align-right">
                  <%= form.hidden_field :creator_id, value: @current_user.id %>
                  <label>制表：</label><span class="margin-right-20"><%= @current_user.full_name %></span>
                  <label>日期：</label><span class="margin-right-20"><%= Date.today.strftime("%Y/%m/%d") %></span>
                </div>
              </td>
            </tr>
            <tr>
              <th>处理</th>
              <td colspan="5">
                <ul>
                  <li><span id="operate-type"><%= type == "StoreReward" ? "奖励" : "扣款" %></span> <%= form.number_field :amount %> 元</li>
                </ul>
              </td>
            </tr>
          </tbody>
        </table>
        <div class="btn_group">
          <%= form.submit "保存", class: "btn save_btn", style: "float:rightmargin-right:240px;;"%>
        </div>
      <% end %>
    </div>
  </div>
</div>



<% content_for :thiny_assets do %>
<script type="text/javascript" charset="utf-8">
  $(document).ready(function(){

    $(".reward-sort, .penalty-sort, .overtime-sort").hide();
    var head_class = "";
    var tr_sort = "";
    var class_name = "";
    var span_operate_type = $("span#operate-type")
    var span_hidden_field = $("#type-hidden");
    $(".option_nav input[type=radio]").on("click", function(){
      $(this).parents("li").siblings("li").find("input[type=radio]").removeAttr("checked");
      head_class = "#" + $(this).data("head");
      tr_sort = $(this).data("sort");
      operate_type = $(this).data("operate")
      switch ($(this).data("head")) {
        case "attendence": class_name = "attendance"; break;
        case "reward": class_name = "reward"; break;
        case "penalty": class_name = "punishment"; break;
        case "overtime": class_name = "reward"; break;
      }
      $("tbody#tbody-class-swift").attr("class", class_name).show();
      $(head_class).show()
             .siblings().hide();

      $(tr_sort).siblings().hide()
                           .find("input").attr("disabled", "disabled");

      $(tr_sort).show()
                .find("input").removeAttr("disabled");

      span_operate_type.text(operate_type);
      span_hidden_field.val($(this).data("type"));
    })

  })

  $("tr.attendence-sort input").on("click", function(){
    if($(this).attr("id") == 'store_staff_event_sort_2' || $(this).attr("id") == 'store_staff_event_sort_17'){
      $("input#store_staff_event_amount").attr("disabled", "true")
    }else {
      $("input#store_staff_event_amount").removeAttr("disabled")
    };
    $(".reward-sort, .penalty-sort, .overtime-sort").find("input").attr("disabled", "disabled");
    // $("tr.attendence-sort").find("input").removeAttr("disabled");

  })
</script>
<% end %>
